from PyQt4.Qt import SIGNAL
from PyQt4.QtGui import QPushButton, QApplication, QGraphicsView, QGraphicsScene, QVBoxLayout, QMainWindow
from logging import getLogger, config
from dodo.mindmap.data.managers import NodeManager
from dodo.mindmap.widgets import NodeWidget
from dodo.mindmap.data.models import MindmapModel
import sys

config.fileConfig('logging.conf')
logger = getLogger('dodo.mindmap')

class IDEAvolution:
    """
    IDEAvolution is the main application class.
    
    It stores all of the data, is in charge of saving and updating data from the network
    and registers all nodes with their corresponding graphical elements.
    """
    def __init__(self):
        # Initialize the models
        self.map = MindmapModel()
        
        # Initialize the QApplication
        self.app = QApplication(sys.argv)
    
        self.window = IDEAvolutionMainWindow()
        #main_widget.setLayout(layout)
        self.window.resize(250, 150)
        self.window.setWindowTitle('IDEAvolution')
        self.window.show()
        
        self.app.exec_()
        
    def add_node(self):
        self.map.add_vertices(1)
        self.window.scene.addItem(NodeWidget())

class IDEAvolutionMainWindow(QMainWindow):
    
    def __init__(self):
        super(IDEAvolutionMainWindow, self).__init__()
        self.start()
        
    def start(self):
        logger.info("Running initialization code")
        self.view = MindmapView()
        self.scene = Mindmap(self)
        self.view.setScene(self.scene)
        
        logger.info("Starting main widget")
        self.setCentralWidget(self.view)
        
    def addWidgets(self):
        self.hellobutton = QPushButton("Say 'Hello world!'",None)
        self.connect(self.hellobutton, SIGNAL("clicked()"), self.slotSayHello)
        self.hellobutton.show()
        
    def slotSayHello(self):
        """ This is an example slot, a method that gets called when a signal is 
            emitted """
        print "Hello, World!"

class MindmapView(QGraphicsView):
    """
    MindmapView controls the viewport for the Mindmap QGraphicsScene object.
    
    It caputures zoom- and pan-related mouse events and passes the remaining events on
    to the scene to deliver to the nodes and other elements.
    """
    pass

class Mindmap(QGraphicsScene):
    """
    Mindmap stores the graphics for the Mindmap.
    
    It registers clicks on nodes, maintains the state of the map and 
    """
    
    def __init__(self, parent):
        super(Mindmap, self).__init__(parent)
        
        self.addItem(NodeWidget())